package com.woniuxy.educationplatform.mapper;

import com.woniuxy.educationplatform.bean.ProjectBean;
import com.woniuxy.educationplatform.bean.TeacherBean;
import com.woniuxy.educationplatform.bean.VideoBean;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;
@Mapper
public interface TeacherMapper {
    @Results({
            @Result(id = true,property = "id",column = "id",javaType = Long.class),
            @Result(property = "teacherName",column = "teacher_name",javaType = String.class),
            @Result(property = "image",column = "image",javaType = String.class),
            @Result(property = "descr",column = "descr",javaType = String.class),
            @Result(property = "projectBean",column = "fk_project_id",javaType = ProjectBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.ProjectMapper.findById",fetchType = FetchType.LAZY)),
            @Result(property = "videoId",column = "fk_video_id",javaType = Long.class),
            @Result(property = "videoImage", column = "video_image",javaType = String.class)
    })
    @Select("select * from teacher")
    List<TeacherBean> findAll();

    @Results({
            @Result(property = "projectBean",column = "fk_project_id",javaType = ProjectBean.class,one =
            @One(select = "com.woniuxy.educationplatform.mapper.ProjectMapper.findById",fetchType = FetchType.LAZY)),
            @Result(property = "videoId",column = "fk_video_id",javaType = Long.class),
            @Result(property = "videoImage",column = "video_image", javaType = String.class)
    })
    @Select("select id,teacher_name as teacherName,image,video_image,descr,fk_project_id,fk_video_id,recommend from teacher where id = #{id}")
    TeacherBean findById(Long id);

    /**
     * 更新老师
     * @return
     */
    int update(@Param("t") TeacherBean teacherBean);

    @Delete("delete from teacher where id = #{id}")
    int del(Long id);

    List<TeacherBean> findByCondition(@Param("t")TeacherBean teacherBean);

    @Select("select proj_name from project")
    String[] getProject();

    @Select("select teacher_name from teacher")
    String[] getTeacher();

    @Insert("insert into teacher (fk_project_id,teacher_name,image,descr,fk_video_id,video_image,recommend)" +
            "values (#{t.projectBean.id},#{t.teacherName},#{t.image},#{t.descr},#{t.videoId},#{t.videoImage}," +
            "1)")
    int add(@Param("t") TeacherBean teacherBean);

}
